In computer programming the term "variable" is used to refer to a named storage location capable of containing a certain type of data that can be accessed and/or modified during execution of the program. A global variable is a variable that may be accessed by any function, statement or piece of code in a program. Typically, global variables are initialized to a default value upon each start-up of a computer program. Some programming languages allow only simple initializations of global variables, i.e. initializations of simple expressions or constant values. However, other programming languages, such as "C++," allow complex initializations of global variables, i.e. the evaluation of function calls or complex routines.
During every start-up of a computer program, some amount of time is consumed by the initialization of all the global variables. Complicated C++ programs may contain hundreds or even thousands of global variables requiring complex initialization. Thus, a common problem associated with large C++ programs is a significant latency in start-up time due to the initialization of global variables.
A C++ compiler converts source code (human-readable program statements written in a high-level or assembly language) into machine-readable object code, which is stored in object files. Object files are linked together, along with library files, to produce an computer program, comprising an executable file and zero or more dynamic link libraries. During compilation of the source code, when a C++ compiler encounters an uninitialized global variable of sufficient complexity and requiring initialization, the compiler generates and stores in the object file an additional function (or segment of computer code) called an "initializer." After the object files are linked with the library files, the initializer will become part of the computer program. The initializer will be responsible for initializing the global variable upon start-up of the computer program. A complicated C++ program having hundreds or thousands of global variables will have a corresponding number of initializers.
A prior art method for reducing the latency involved in processing initializers upon start-up of a computer program is to optimize the initializer in the object file prior to creation of the executable file. In the past, compilers have been configured to perform optimizations on the object code that makes up an initializer. Prior art compilers have been configured with the ability to eliminate needless function calls, simplify expressions and generally cause the initializer object code to be smaller and faster. Thus, when the object file is linked with library files, the optimized initializer is incorporated into the computer program and the latency associated with the initialization of global is reduced.
Still, configuring a compiler to optimize an initializer in an object file typically does not allow for complete exclusion of the initializer from the computer program. Often, a compiler will be able to reduce an initializer to a single instruction. However, a compiler generally does not have the ability to speculatively execute an instruction to see what the result would be if it were executed by a fully operational computer program. Thus, even if the compiler is able to reduce the initializer to a single instruction, this instruction will still have to be processed upon every start-up of the computer program. As such, even initializer optimization is generally not fully effective to reduce latency involved with the initialization of global variables for a complicated C++ program having hundreds or thousands of initializers.
Accordingly, there remains a need in the art for a system and method for pre-executing an initializer prior to creation of a computer program. There also remains a need for a system and method for excluding an initializer from an computer program so as to eliminate latency caused by processing the initializer upon start-up of the computer program.